package com.techsen.tsweb.sys.domain;

import com.techsen.tsweb.core.domain.BaseEntity;
import com.techsen.tsweb.sys.security.AclPermission;
import com.techsen.tsweb.sys.security.Resource;

/**
 * 操作
 */
public class Oper extends BaseEntity<Oper> implements Resource {

    private static final long serialVersionUID = -3802590690974793852L;

    /**
     * 操作名
     */
    private String name;
    
    /**
     * 前端操作的处理器
     */
    private String handler;
    
    /**
     * 操作的图标类
     */
    private String iconCls;
    
    /**
     * 方法名<br/>
     * 可能有多个，用"|"隔开
     */
    private String methodNames;
    
    /**
     * ACL索引
     */
    private Integer aclIndex;
    
    /**
     * 所属控制器ID
     */
    private String controllerId;
    
    /**
     * 所在菜单ID
     */
    private String menuId;

    public String getName() {
        return name;
    }

    public Oper setName(String name) {
        this.name = name;
        return this;
    }

    public String getHandler() {
        return handler;
    }

    public Oper setHandler(String handler) {
        this.handler = handler;
        return this;
    }

    public String getIconCls() {
        return iconCls;
    }

    public Oper setIconCls(String iconCls) {
        this.iconCls = iconCls;
        return this;
    }

    public String getMethodNames() {
        return methodNames;
    }

    public Oper setMethodNames(String methodNames) {
        this.methodNames = methodNames;
        return this;
    }

    public Integer getAclIndex() {
        return aclIndex;
    }

    public Oper setAclIndex(Integer aclIndex) {
        this.aclIndex = aclIndex;
        return this;
    }

    public String getControllerId() {
        return controllerId;
    }

    public Oper setControllerId(String controllerId) {
        this.controllerId = controllerId;
        return this;
    }

    public String getMenuId() {
        return menuId;
    }

    public Oper setMenuId(String menuId) {
        this.menuId = menuId;
        return this;
    }

    /**
     * 资源类型
     */
    @Override
    public String getResourceType() {
        return this.getClass().getSimpleName().toLowerCase();
    }

    /**
     * 所属资源组ID
     */
    @Override
    public String getResourceGroup() {
        return this.menuId;
    }

    /**
     * 资源标识
     */
    @Override
    public String getResourceSn() {
        return id;
    }

    /**
     * 访问控制码
     */
    @Override
    public Integer getAclCode() {
        return aclIndex == null ? AclPermission.NONE_PERMISSION_TOKEN : 1 << aclIndex;
    }
    
}
